package cn.wolfcode.producer_02._02_send_type;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

public class Producer1 {
    public static void main(String[] args) throws Exception {
        //1 创建信息的发送者
        DefaultMQProducer defaultMQProducer = new DefaultMQProducer("product-demo2");
        //2 设置名字服务
        defaultMQProducer.setNamesrvAddr("127.0.0.1:9876");
        //3 启动生产者
        defaultMQProducer.start();
        //4 创建信息
        //4.1 创建消息对象
        Message message = new Message("02-send-type", "Hello RocketMQ".getBytes());
        defaultMQProducer.sendOneway(message);
//        System.out.println(sendResult.getSendStatus());//查看发送的状态
//        System.out.println(sendResult.getMsgId());//查看消息的id
        //5 关闭连接
        defaultMQProducer.shutdown();
    }
}
